import api from "../../utils/api_util";
import tips from "../../utils/tip";
import base_util from "../../utils/base_util";

const app = getApp();
Page({
    data: {
        StatusBar: app.globalData.StatusBar,
        CustomBar: app.globalData.CustomBar,
        images: [],
        category: '',
        content: '',
        FeedbackList: [{
            id: 13,
            title: '功能异常',
            titledes: '不能正确使用现有功能'
        },
            {
                id: 2,
                title: '使用建议',
                titledes: '用的不满意的地方都提过来吧'
            },
            {
                id: 3,
                title: '功能需求',
                titledes: '现有功能不能满足'
            },
            {
                id: 4,
                title: '系统闪退',
                titledes: '意外退出，闪退'
            },
            {
                id: 5,
                title: '其他',
                titledes: '其他'
            }
        ]
    },
    onLoad: function (options) {

    },
    radioChange(e) {

        this.setData({
            category: e.detail.value,
        })
        console.log(e.detail.value);
    },
    chooseImage(e) {
        let that = this;
        wx.chooseImage({
            count: 1, // 默认9
            sizeType: ['original', 'compressed'],
            sourceType: ['album', 'camera'],
            success: res => {

                that.doUpload(res.tempFilePaths);
            }
        })
    },
    doUpload: function (tempFilePaths) {
        let that = this;
        wx.uploadFile({
            url: api.urls.fileUpload,
            filePath: tempFilePaths[0],
            name: 'file',
            // formData: {
            //     'id': that.roomId
            // },
            header: {
                'token': base_util.getStorageSync('token') ? base_util.getStorageSync('token') : '',
            },
            success(res) {
                // tipUtil.loaded();
                let data = JSON.parse(res.data);
                let images = [...that.data.images, api.urls.imgUrl + data.data.file[0]];
                that.setData({
                    images: images
                });
                console.log(data.data.file)

            },
        })
    },
    removeImage(e) {

        let iindex = e.target.dataset.index;
        this.setData({
            images: this.data.images.filter((item, index) => index != iindex)
        })
        wx.showToast({
            title: "图片已删除"
        })
    },

    //提交反馈信息
    feedbackPost: function () {
        let that = this;
        api.wxRequest.apiRequest(that, api.urls.feedbackCreate, {
            method: 'POST',
            data: {
                content: that.data.content,
                category: that.data.category,
                image: (that.data.images.toString()).replace(/,/g, "||"),
                v: '1.0.0'
                // image: '1.0.0',
            },
            success: function (res) {
                setTimeout(function () {
                    tips.alert('提交成功~')
                }, 100)

                setTimeout(function () {
                    base_util.pageJump("../My/My", true);
                }, 1000)
            },
        })
    },
    textareaChange: function (e) {
        this.setData({
            content: e.detail.value
        })
    }
})